#include"Chapter2_CoutAndCin.h"
#include"HelloWorld.h"
#include<iostream>
#include<cmath>
#include <iomanip>
#include <random>
#define M_PI 3.14159265358979323846
using namespace std;


//第二天胡萝卜输入加2
void carrots() {
	std::cout << "how many carrots do you have?\n"
	<< "\n" << "two line"
	<< "\n";
	int carrots=1;
	//cin >> carrots;
	cout << "here are two more." << "/n";
	carrots = carrots + 2;
	cout << "now you hava:" << carrots << "carrots." << '\n';
	cout<<"This is Carrots construct"<< '\n';
}
// 非成员函数实现
void contInt(){
	//using namespace std;//using 编译指令，作用是代替std::,这句语句 名称空间 
	int i = 10;
	int j;
	j = 1;
	cout << "hello contInt!" << '\n';
	//cout << "Come up and C++ me some time.";
	cout <<'\n';
	cout << "I:"<<i <<",J="<<j<< '\n';
	//cin.get();//c++98的新特性,让控制台 一直打开
	cout << i << '\n';
};
float resqrt(float i) {
	//float j = sqrt(i);
	return  sqrt(i);
}
void day2() {	
	//创建 Carrots 类的一个对象
	carrots();
	contInt();
	cout << fixed << setprecision(5);//所有的浮点数都会保留5位
}	
//for循环pow();rand()%100+1 and srand()	;定义πand cout << fixed << std::setprecision(5);sqrt()平方根;bucks()美元;
void day3() {
	cout <<"M_PI is:" << M_PI<<'\n';
	double x = sqrt(8);//32位
	cout <<"double x=" << x <<'\n';
	
	//强行转化成整数
	x = static_cast<int>(pow(2, 3));
	// cout << x << '\n';
	cout <<"pow(2, 3)="<< x <<'\n';
	int k =  rand();
	// 使用当前时间作为随机数生成的种子
	srand(static_cast<unsigned int>(time(nullptr)));
	//循环多少次
	for (int i = 1; i <= 5;i++) {
		cout <<"第:"<< i <<"次，随机数:"<<k  % 100 + 1 << '\n';
	}	
}
void day4()
{
	int j;
	cout<<"input cin is:";cin>>j;cout<<'\n';
	//在头文件声明public
	HelloWorld h;	
	int result = h.hw(j);	
	cout<<"helloWorld i="<<result<<'\n';
}
int days_between_dates(time_t  time1, time_t  time2) {
	// 计算两个时间之间的差值（秒）
	double seconds = difftime(time2, time1);	
	// 将秒转换为天数
	int days = (int)(seconds / (60 * 60 * 24));
	return days;
}
//struct tm格式时间的输出打印。
void get_past_date_buffer(struct tm past_date)
{	
	char past_date_buffer[26];
	asctime_s(past_date_buffer, 26, &past_date);
	std::cout << "past_time: " << past_date_buffer;
	
}
void lose_weight(int day)
{
	std::cout << "Burn off: " << day*41 << "g"<<std::endl;
	double Brunoff= day*41.0/1000 ;
	std::cout << "Burn off: " << std::fixed << std::setprecision(2)<<Brunoff<< "kg"<<std::endl;
}
//减肥计算器猫点日期11.12
void day5()
{
	cout<<"hi,my NO.5 day C++ study"<<'\n';
	//定义锚定日期
	struct tm past_date  = {0, 0, 0, 12, 10, 2024 - 1900};
	

	/*char past_date_buffer[26];
	asctime_s(past_date_buffer, 26, &past_date);*/
	
	// 获取锚定时间（UTC）
	time_t past_time = mktime(&past_date);	
	// 获取当前时间（UTC）
	time_t now = time(nullptr);
	// 使用 localtime_s 函数获取本地时间
	struct tm local_time;
	localtime_s(&local_time, &now);

	// 使用 asctime_s 函数获取字符串表示
	char buffer[26]; // 足够大小的缓冲区
	
	asctime_s(buffer, 26, &local_time);
	// 输出日期和时间
	std::cout << "Now_time:  " << buffer;
	
	
	int days_diff = days_between_dates(past_time, now);
	cout << "run have days: " << days_diff<<" day!"<<'\n';
	lose_weight(days_diff);
}
//函数的实现
void bucks(double s) {
	cout << fixed << setprecision(2);
	cout << "$" << s << '\n';
};

void day6()
{
	cout<<"my name is zyf，my adress is 怀柔区/乐园大街/10-3-102"<<endl;
	/*cout<<"输入long：";//1long = 200 ma.输出ma
	double distence=0;
	cin >> distence;
	cout << fixed << setprecision(0)<<"ma:"<<distence*200<<'\n';
	cout << fixed << setprecision(1)<<"华氏温度:"<<distence*1.8+32.0<<'\n';*/
	
	/*int h_time=0;
	int m_time=0;
	cout << "输入小时数:";
	cin >> h_time;
	cout << "输入分钟数:";
	cin >> m_time;
	cout <<"Time:"<< h_time<<":"<<m_time<<'\n';*/

	//天文单位:地球到太阳的距离约等于1.5亿公里.一光年10万亿公里
	//一光年 =63240天文单位。要求输入光年转成天文单位,
	double light_years = 0 ;
	cout<<"Enter the number of light years:";cin>>light_years;
	double astronomical_units = light_years*63240;
	cout<<light_years<<" light years = "<<astronomical_units<<" astronomical units."<<endl;
	
};

/*
int main() {
	day6();
	//day5();
	//day4();
	//day3();
	//day2();
	//bucks(100.5);
	return 0; 
}
*/
